package com.simple.simple_view.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.simple.simple_view.domain.system.SystemParam;
import com.simple.simple_view.utils.UidUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Random;

/*
 *@description: TODO
 *@author: hisen
 *@Time: 2023/10/27  1:39
 */
@Component
public class MybatisPlusHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("avatar", SystemParam.QINIU_DEFAULT_AVATAR_PREFIX+(new Random().nextInt(1000) + 1)+SystemParam.QINIU_DEAFAULT_AVATAR_TYPE,metaObject);
        this.setFieldValByName("uid", UidUtil.getUid(12),metaObject);
        this.setFieldValByName("createTime", new Date(), metaObject);
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", new Date(), metaObject);
    }
}
